<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-input
        style="width: 40%"
        placeholder="请输入内容"
        class="input-with-select"
      >
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <el-table :data="list" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="{ row }">
            <el-tag v-if="row.order_pay === '0'" effect="dark" type="danger"
              >未支付</el-tag
            >
            <el-tag v-else effect="dark" type="success">已支付</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="{ row }">
            {{ row.create_time | formatTime }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="{ row }">
            <el-button
              size="mini"
              @click="editCatedialogVisible = true"
              type="primary"
              icon="el-icon-edit"
            >
            </el-button>
            <el-button
              size="mini"
              @click="showExpress(row)"
              type="success"
              icon="el-icon-location"
            >
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryData.pagenum"
        :page-sizes="[1, 2, 4, 6, 10]"
        :page-size="queryData.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>

    <!--  -->
    <el-dialog
      title="修改收货地址"
      :visible.sync="editCatedialogVisible"
      width="50%"
    >
      <el-cascader v-model="cityValue" :options="cityData"></el-cascader>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editCatedialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editCatedialogVisible = false">
          确 定
        </el-button>
      </span>
    </el-dialog>
    <!-- 物流进度对话框 -->
    <el-dialog
      title="物流进度"
      :visible.sync="expressCatedialogVisible"
      width="50%"
    >
      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(item, index) in expressList"
          :key="index"
          :timestamp="item.time"
        >
          {{ item.content }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data() {
    return {
      cityData: cityData,
      cityValue: [],
      queryData: {
        query: '',
        pagenum: 1,
        pagesize: 2
      },
      // 表格数据
      list: [],
      total: 0,
      editCatedialogVisible: false, // 控制显示编辑收获
      expressCatedialogVisible: false, // 物流进度对话框
      expressList: [],
      reverse: true
    }
  },

  created() {
    this.getOrdersList()
  },

  methods: {
    async getOrdersList() {
      const res = await this.$axios.get('/orders', {
        params: this.queryData
      })
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.total = res.data.total
      this.list = res.data.goods
    },
    handleSizeChange(val) {
      this.queryData.pagesize = val
      this.getOrdersList()
    },
    handleCurrentChange(val) {
      this.queryData.pagenum = val
      this.getOrdersList()
    },
    async showExpress(row) {
      this.expressCatedialogVisible = true
      const res = await this.$axios.get('http://localhost:8080/api/express')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.expressList = res.data
    }
  }
}
</script>

<style scoped lang='less'>
</style>
